package com.example.wechat.csdnandroid.activity;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.wechat.csdnandroid.R;
import com.example.wechat.csdnandroid.adapter.FruitRecyclerViewAdapter;
import com.example.wechat.csdnandroid.bean.Fruit;

import java.util.ArrayList;

public class RecyclerViewActivity extends AppCompatActivity {

    private RecyclerView rvArv;
    private ArrayList<Fruit> data = new ArrayList<>();
    private static final String TAG = "RecyclerViewActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view);


        initView();
        initData();
    }

    private void initData() {
        initFakeData();
        //线性布局
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        //网格布局
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 4, RecyclerView.HORIZONTAL, true);
        //瀑布流布局
        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
        rvArv.setLayoutManager(linearLayoutManager);
        FruitRecyclerViewAdapter fruitRecyclerViewAdapter = new FruitRecyclerViewAdapter(data, this);
        rvArv.setAdapter(fruitRecyclerViewAdapter);


    }

    private void initFakeData() {
        Fruit fruit = new Fruit();
        fruit.setPicText("appale  ashddddddddddddddddddddddddasdnaskjdhasjk");
        fruit.setPicImageRes(R.mipmap.appale);
        data.add(fruit);
        Fruit fruit1 = new Fruit();
        fruit1.setPicText("orange ashddddddddddddddddddddddddasdnaskjdhasjk");
        fruit1.setPicImageRes(R.mipmap.orange);
        data.add(fruit1);
        Fruit fruit2 = new Fruit();
        fruit2.setPicText("mango");
        fruit2.setPicImageRes(R.mipmap.mango);
        data.add(fruit2);
        Fruit fruit3 = new Fruit();
        fruit3.setPicText("pear aaaaaaaaaaaaaaaaaaaaaaaaaaaashddddddddddddddddddddddddasdnaskjdhasjkashddddddddddddddddddddddddasdnaskjdhasjkashddddddddddddddddddddddddasdnaskjdhasjkashddddddddddddddddddddddddasdnaskjdhasjk");
        fruit3.setPicImageRes(R.mipmap.pear);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);
        data.add(fruit3);


    }

    private void initView() {
        rvArv = (RecyclerView) findViewById(R.id.rv_arv);
    }
}
